package leetcode_acm.array;

/**
 * 功能描述
 *
 * @author: 张庭杰
 * @date: 2023年03月17日 14:34
 */
public class CountNodes {
    private class TreeNode{
        int val;
        TreeNode left;
        TreeNode right;

        public TreeNode(int val) {
            this.val = val;
        }
    }
    public int countNodes(TreeNode root) {
        if(root == null){
            return 0;
        }
        int ll = 0;
        TreeNode cur = root;
        while(cur != null){
            ll++;
            cur = cur.left;
        }
        int rr = 0;
        cur = root;
        while (cur != null){
            rr++;
            cur = cur.right;
        }
        if(ll == rr){
            return (2<<ll) -1;
        }
        return countNodes(root.left)+countNodes(root.right)+1;
    }
}
